var vm = new Vue({
  el : '#app',
  extends: CommonTools,
  
  data : function() {
    return {
      leave:{
    	  apName:'',
    	  leStart:'',
    	  leEnd:'',
    	  leCause:''
      },
      teaOptions:{},
      teacher:{},
      show : false,
      leaveId:'',
      
    }
    
  },
  
  filters: {
    /**
     * 状态名称
     */
    stateName(state) {
      for (var i = 0; i < vm.states.length; ++i) {
        if (vm.states[i].value == state) {
          return vm.states[i].label;
        }
      }
      return state;
    },
    
  },
  
 /* computed: {
  readonly: function(){
      return this.activity && (this.activity.state != 'uncommit');
    },
    
    
  },*/
  
  methods: {
    
    /**
     * 重新加载单据
     */
	  reload(){
	      var self = this;
	      var url = "gLeaveController.do?get&id=" 
	        + (this.leaveId?this.leaveId:'');
	      this.get(url).then((data) => {       
	        self.leave = data;
	        if(self.leave != null){
	        	if(self.leave.apResult !="unsubmit"){
	        		self.show = true;
	        	}
	        }
	      }).catch(err => {
	        this.showError(err);
	      });
	    },
    
    /**
     * 保存操作
     */
    onSave() {
        var self = this;
        return self.doSave();
      },

    /**
     * 保存
     */
    doSave(){
      var self = this;
      var url = 'gStudentController.do?doAdd2';
      self.leave.apName=self.teacher.name;
      self.leave.apCode=self.teacher.teaNum;
      self.leave.apResult="unsubmit";
      self.leave.leName=JSON.parse(sessionStorage.user).name;
      self.leave.leNum=JSON.parse(sessionStorage.user).stuNum;
        self.post(url, self.leave).then(() => {
          self.showMsg('操作成功！', function() {
            self.goback();
          });
        }).catch(err => {
          self.showError(err);
        });
    },
    
    goback(){
      history.back();
    },
    /**
     * 删除请假单单
     */
    onAgree(){
      var self = this;
      var url = 'gLeaveController.do?agree&id=' + self.leave.id;
      this.confirm('确认要批准这个请假单吗？', function() {
        self.get(url).then(() => {
          self.showMsg('操作成功！', function() {
            self.goback();
          });
        }).catch(err => {
          self.showMsg('操作失败');
        });
      });
    },
    /**
     * 提交请假单单
     */
    onRefuse(){
    	var self = this;
    	var url = 'gLeaveController.do?refuse&id=' + self.leave.id;
    	this.confirm('确认要拒绝这个请假单吗？', function() {
    		self.get(url).then(() => {
    			self.showMsg('拒绝成功！', function() {
    				self.goback();
    			});
    		}).catch(err => {
    			self.showMsg('拒绝失败');
    		});
    	});
    },
    
    
  },
  
  created() {
    this.leaveId = this.getQueryParam('id');
    this.reload();
  },
  
});
